package compare;

class Person implements Comparable<Person>{
	String name;
	int age;
	public Person(String name, int age) {
		this.name = name;
		this.age = age;
	}
	
	@Override
	public String toString() {
		return "Person [name=" + name + ", age=" + age + "]";
	}
	// 对象大返回正，参数大返回负，一样大返回0
	@Override
	public int compareTo(Person o) {
//		return this.age - o.age;
		return this.name.compareTo(o.name);
	}
}
public class ComparableDemo {
	public static void main(String[] args) {
		Person p1 = new Person("lis",20);
		Person p2 = new Person("zs",30);
		//两个对象比较大小？只有数字类型可以使用> <,>=,<=
		System.out.println(p1.compareTo(p2));
	}
}
